#include "RsGisLibCalImageMath.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibCalImageMath::RsGisLibCalImageMath(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibImageCalImageMath();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_InputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_InputFilePath_clicked()));
	connect(ui->pushButton_OutputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_OutputFilePath_clicked()));
	connect(ui->pushButton_ApplyImage, SIGNAL(clicked()), this, SLOT(on_action_Button_ImageApply_clicked()));

	ui->lineEdit_ImageMathExpression->setText(
		"b1 * 100"
	);

	QStringList DatatypeList;
	DatatypeList.append("undefined");
	DatatypeList.append("8 Int");
	DatatypeList.append("16 Int");
	DatatypeList.append("32 Int");
	DatatypeList.append("64 Int");
	DatatypeList.append("8 uInt");
	DatatypeList.append("16 uInt");
	DatatypeList.append("32 uInt");
	DatatypeList.append("64 uInt");
	DatatypeList.append("32 Float");
	DatatypeList.append("64 Float");
	ui->comboBox_Datatype->addItems(DatatypeList);

	ui->lineEdit_InputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\Test.tif");
	ui->lineEdit_OutputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\TestImageMath.tif");
	ui->lineEdit_GdalFormat->setText("GTIFF");
	ui->comboBox_Datatype->setCurrentIndex(10);

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibCalImageMath::on_action_Button_InputFilePath_clicked()
{
	QString str = QFileDialog::getOpenFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_InputFilePath->setText(str.toUtf8());
}

void RsGisLibCalImageMath::on_action_Button_OutputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_OutputFilePath->setText(str.toUtf8());
}

void RsGisLibCalImageMath::on_action_Button_ImageApply_clicked()
{
	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("imageCalculation"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("ImageMaths"));
	AlgParaList << QVariant(QString(ui->lineEdit_InputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_OutputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_ImageMathExpression->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_GdalFormat->text()));
	AlgParaList << QVariant(int(ui->comboBox_Datatype->currentIndex()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}
